##
##  $Header: /pub/cvsroot/mydns/doc/texi/Makefile.am,v 1.2 2002/09/20 20:16:15 bboy Exp $
##

EXTRA_DIST		=	$(TEXI) configuration.texi database.texi fdl.texi \
						installation.texi introduction.texi references.texi \
						server.texi title.texi troubleshooting.texi \
						utilities.texi

TEXIVARS			=	variables.texi
TARGETDIRS		=	../html ../info

TEXI				=	@PACKAGE_NAME@.texi
INFO				=	$(TEXI:texi=info)
HTML				=	$(TEXI:texi=html)
DEPS				=	$(TEXI) $(TEXIVARS)

RUN				=	$(SHELL) $(top_srcdir)/missing --run


targetdirs:
	for d in $(TARGETDIRS); do if ! test -d $$d; then mkdir $$d; fi; done

## Create a .texi file including the variables
variables.texi:
	@if `test -f $(TEXIVARS)`; then rm -f $(TEXIVARS); fi
	@echo "@set MYDNSCONF @MYDNS_CONF@" >> $(TEXIVARS)
	@echo "@set PKGDATE @PACKAGE_DATE@" >> $(TEXIVARS)
	@echo "@set PKGNAME @PACKAGE_NAME@" >> $(TEXIVARS)
	@echo "@set PKGVERSION @PACKAGE_VERSION@" >> $(TEXIVARS)
	@echo "@set PKGSTRING @PACKAGE_STRING@" >> $(TEXIVARS)
	@echo "@set PKGAUTHOR @PACKAGE_AUTHOR@" >> $(TEXIVARS)
	@echo "@set PKGBUGREPORT @PACKAGE_BUGREPORT@" >> $(TEXIVARS)
	@echo "@set PKGHOMEPAGE @PACKAGE_HOMEPAGE@" >> $(TEXIVARS)
	@echo "@set PKGCOPYRIGHT @PACKAGE_COPYRIGHT@" >> $(TEXIVARS)

vars: targetdirs variables.texi

info: $(DEPS)
	if $(RUN) makeinfo --version | head -1 | grep \[4-9\]\.\[0-9\] > /dev/null 2>&1; then \
	  $(RUN) makeinfo -o ../info/$(INFO) $(TEXI); \
	fi
	@if ! test -f ../info/$(INFO); then \
	  echo; \
	  echo "*** GNU \"info\" documentation not created - you probably need makeinfo."; \
	  echo "*** See http://www.fsf.org/software/texinfo/texinfo.html for details."; \
	  echo; \
	fi

html-doc: $(DEPS)
	$(RUN) perl ../support/texi2html -init_file=../support/texi2html.init $(TEXI)
	@if ! test -f ../html/$(HTML); then \
	  echo; echo "*** HTML documentation not created - you probably need perl"; echo; \
	fi

html-doc-web: $(DEPS)
	if test -d @WEBROOT@; then \
	  $(RUN) perl ../support/texi2html -init_file=@WEBROOT@/doc/texi2html.init $(TEXI); \
	fi

html: html-doc

pdf-create:
	if ! test -d ../pdf; then mkdir ../pdf; fi
	cp -f $(TEXI) tmp.texi
	pdftex --interaction=nonstopmode tmp.texi
	texindex tmp.??
	pdftex --interaction=nonstopmode tmp.texi
	texindex tmp.??
	pdftex --interaction=nonstopmode tmp.texi
	mv tmp.pdf ../pdf/mydns.pdf
	rm -f tmp.*

pdf: $(DEPS) pdf-create

mydns_letter.ps: $(DEPS)
	if ! test -d ../ps; then mkdir ../ps; fi
	MAKEINFO='$(RUN) $(MAKEINFO) -I $(srcdir)' $(RUN) texi2dvi --batch --clean $<
	$(RUN) dvips -t letter mydns.dvi -o ../ps/$@

mydns_a4.ps: $(DEPS)
	if ! test -d ../ps; then mkdir ../ps; fi
	MAKEINFO='$(RUN) $(MAKEINFO) -I $(srcdir)' $(RUN) texi2dvi --batch --clean $<
	$(RUN) dvips -t a4 mydns.dvi -o ../ps/$@

ps: mydns_letter.ps mydns_a4.ps

all: vars info html-doc

clean:
	rm -rf $(TARGETDIRS) ../pdf ../ps
	rm -f *~ core* $(TEXIVARS) mydns.dvi

info-install: info
	if test -f ../info/$(INFO); then \
	  $(INSTALL) -d $(DESTDIR)$(infodir); \
	  $(INSTALL_DATA) ../info/$(INFO) $(DESTDIR)$(infodir)/$(INFO); \
	fi

install: all info-install

## Target the author uses to install docs on the homepage:
release: vars html-doc-web pdf ps
	rm -f ../info/$(INFO)
	rm -f @WEBROOT@/doc/pdf/*.pdf && cp -a ../pdf/*.pdf @WEBROOT@/doc/pdf
	rm -f @WEBROOT@/doc/ps/*.ps && cp -a ../ps/*.ps @WEBROOT@/doc/ps
	rm -f @WEBROOT@/doc/man/*.[0-9] && cp -a ../man/*.[0-9] @WEBROOT@/doc/man

## vi:set ts=3:
